function [s_hat,signal] = alamouti_detector_qpsk(h,r,rho,nt,nr)

theta=[-3*pi/4 3*pi/4 -pi/4 pi/4];
s_try=exp(j*theta);
s_possible=[];
for k=1:4
	temp=[s_try; circshift(s_try, [0 k])];
	s_possible=horzcat(s_possible,[s_try; circshift(s_try, [0 k])]);
end
sum=0;
for k=1:nr
	sum=sum + abs(r(k,1) - h(k,1)*s_possible(1,:) - h(k,2)*s_possible(2,:) ).^2;
	sum=sum + abs(r(k,2) + h(k,1)*conj(s_possible(2,:)) - h(k,2)*conj(s_possible(1,:)) ).^2;
end
[minim,index]=min(sum);
s_hat=s_possible(:,index);


signal=[];
for m=1:length(r)
	signal=horzcat(signal,qpsk2bin(s_hat(m)));
end


